package commercial.src;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("欢迎进入小店！");
        System.out.print("请输入您的姓名：");
        String name = scanner.nextLine();
        System.out.print("请输入您的联系方式：");
        String contact = scanner.nextLine();
        User user = new User(name, contact);


        List<Product> productCatalog = new ArrayList<>();
        productCatalog.add(new Product(1001, "T恤", 79.9, 50, "M"));
        productCatalog.add(new Product(1002, "牛仔裤", 129.9, 30, "L"));
        productCatalog.add(new Product(1003, "运动鞋", 259.0, 20, "42"));
        productCatalog.add(new Product(1004, "外套", 199.9, 10, "XL"));

        System.out.println("\n商品目录：");
        for (Product p : productCatalog) {
            p.displayInfo();
        }

        Order order = new Order(user);
        while (true) {
            System.out.print("\n请输入要购买的商品序列号（输入 0 结束选择）：");
            int serial = scanner.nextInt();

            if (serial == 0) break;

            boolean found = false;
            for (Product p : productCatalog) {
                if (p.getSerialNumber() == serial) {
                    order.addProduct(p);
                    System.out.println("已添加商品：" + p.getName());
                    found = true;
                    break;
                }
            }
            System.out.println("\n商品目录：");
            for (Product p : productCatalog) {
                p.displayInfo();
            }
            if (!found) {
                System.out.println("商品不存在，请重新输入！");
            }
        }

        // ===== 展示订单明细 =====
        System.out.println("\n您选购的商品如下：");
        order.displayOrder();

        // ===== 支付选择 =====
        System.out.println("\n请选择支付方式：");
        System.out.println("1. 信用卡");
        System.out.println("2. 支付宝");
        System.out.println("3. 微信");

        int choice = scanner.nextInt();
        Payment payment = null;
        switch (choice) {
            case 1 -> payment = new CreditCardPayment();
            case 2 -> payment = new AlipayPayment();
            case 3 -> payment = new WeChatPayment();
            default -> {
                System.out.println("无效选择！");
                return;
            }
        }

        order.pay(payment);
    }
}
